<template>
  <!-- 通知 -->
  <div class="home">
    <div class="scroll-container">
      <NoticeBar />
    </div>
    <div class="vip" @click="goPath('pay')">购买VIP</div>
    <div v-if="!isLogin" class="home-btn" @click="showLoginPop = true">
      立即登录
    </div>
    <div v-else class="home-info">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="avatar" src="@/assets/imgs/avatar.jpg" />
          {{ nickname }}
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <span @click="showTokenPop = true"
              ><i class="el-icon-goods"></i> Token消耗记录</span
            >
          </el-dropdown-item>
          <el-dropdown-item>
            <span @click="logout()"
              ><i class="el-icon-switch-button"></i> 退出</span
            >
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="home-top">
      <div class="p1">学术专区</div>
      <div class="p2">探索学术前沿：一站式AI智能解决方案</div>
    </div>
    <div class="home-part">
      <div class="home-title">学术工具</div>
      <div class="home-cards">
        <div v-for="item in navOptions1" :key="item.title" class="card">
          <div class="card-top">
            <img :src="item.imgUrl" alt="" />
            {{ item.title }}
          </div>
          <div class="card-con">
            <div class="text">
              <div class="desc">{{ item.des1 }}</div>
              <div class="desc">{{ item.des2 }}</div>
            </div>
            <div class="btn" @click="goPath(item.path)">
              立即体验
              <i class="el-icon-arrow-right"></i>
            </div>
          </div>
        </div>
      </div>
      <div class="home-title mt">非学术工具</div>
      <div class="home-cards">
        <div v-for="item in navOptions2" :key="item.title" class="card">
          <div class="card-top">
            <img :src="item.imgUrl" alt="" />
            {{ item.title }}
          </div>
          <div class="card-con">
            <div class="text">
              <div class="desc">{{ item.des1 }}</div>
              <div class="desc">{{ item.des2 }}</div>
            </div>
            <div class="btn" @click="goPath(item.path)">
              立即体验
              <i class="el-icon-arrow-right"></i>
            </div>
          </div>
        </div>
      </div>
    </div>
    <LoginPop :show.sync="showLoginPop" @onClose="close" />
    <TokenPop :show.sync="showTokenPop" />
  </div>
</template>

<script>
import { navOptions1, navOptions2 } from "../../utils/config";
import LoginPop from "@/components/LoginPop.vue";
import TokenPop from "@/components/TokenPop.vue";
import NoticeBar from "@/components/NoticeBar.vue";
export default {
  name: "Index",
  components: {
    LoginPop,
    TokenPop,
    NoticeBar,
  },
  data() {
    return {
      isLogin: localStorage.getItem("userinfo") ? true : false,
      nickname: localStorage.getItem("userinfo")
        ? JSON.parse(localStorage.getItem("userinfo")).nickname
        : "小魔仙",
      navOptions1,
      navOptions2,
      showLoginPop: false,
      showTokenPop: false,
    };
  },
  methods: {
    goPath(path) {
      if (this.isLogin) {
        this.$router.push(path);
      } else {
        this.showLoginPop = true;
      }
    },
    close(nickname) {
      this.isLogin = true;
      this.nickname = nickname;
    },
    logout() {
      localStorage.removeItem("userinfo");
      this.isLogin = false;
    },
    goBuy() {
      this.$router.push("/pay");
    },
  },
};
</script>

<style lang="less" scoped>
.home {
  min-width: 1200px;
  height: 100%;
  padding-bottom: 80px;
  overflow: auto;
  background-color: #f9fdff;
  position: relative;

  .scroll-container {
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 24px;
    width: 25%; /* 宽度 */
    height: 20%; /* 高度 */
    height: 24px;
  }

  .vip {
    position: absolute;
    top: 24px;
    right: 170px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(105, 101, 234, 0.3);
    border: 1px solid rgba(105, 101, 234, 0.4);
    border-radius: 5px;
    padding: 0 13px;
    color: #434343;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    &:hover {
      background: rgba(105, 101, 234, 0.4);
    }
  }
  .home-btn {
    position: absolute;
    right: 30px;
    top: 20px;
    width: 92px;
    height: 32px;
    background: #ffffff;
    box-shadow: inset -2px -2px 14px 1px #703ffc29;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    font-family: "\82f9\65b9-\7b80-\4e2d\9ed1\4f53, \82f9\65b9-\7b80";
    font-weight: 400;
    color: #6965ea;
  }
  .home-info {
    position: absolute;
    right: 30px;
    top: 20px;
    height: 32px;
    cursor: pointer;
    .el-dropdown-link {
      height: 32px;
      display: flex;
      align-items: center;
      .avatar {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        margin-right: 10px;
        background-color: #6965ea;
      }
    }
    .el-icon-switch-button {
      margin-right: 10px;
    }
    /deep/ .el-dropdown {
      font-size: 14px;
      color: #fff;
    }
  }
  .home-top {
    height: 340px;
    background: url("../../assets/imgs/home_bg.png") top no-repeat;
    background-size: 100% 340px;
    background-color: hsl(200, 100%, 99%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-content: center;
    justify-content: center;
    .p1 {
      font-size: 40px;
      font-weight: 600;
      color: #fff;
      font-family: PingFang SC-Semibold, PingFang SC;
      text-shadow: 0px 7px 26px rgba(23, 19, 121, 0.46);
    }
    .p2 {
      font-size: 14px;
      font-weight: 400;
      color: #fff;
      margin-top: 11px;
    }
  }
  .home-part {
    margin: 0 auto;
    text-align: left;
    width: 1200px;
    padding: 0 57px 0 81px;
    box-sizing: border-box;
    .home-title {
      font-size: 14px;
      font-family: PingFang SC-Semibold, PingFang SC;
      font-weight: 600;
      color: #080a25;
      margin-bottom: 21px;
      &.mt {
        margin-top: 40px;
      }
      &::before {
        content: "";
        display: inline-block;
        width: 3px;
        height: 14px;
        background: rgba(105, 101, 234, 0.5);
        border-radius: 0 2px 2px 0;
        vertical-align: middle;
        margin-right: 10px;
        position: relative;
        top: -1px;
      }
    }
    .home-cards {
      display: flex;
      flex-wrap: wrap;
      .card {
        margin-right: 24px;
        box-shadow: 0 8px 8px 1px #0000000a;
        border-radius: 12px;
        border: 1px solid #ffffff;
        height: 210px;
        width: 328px;
        margin-bottom: 25px;
        .card-top {
          display: flex;
          align-items: center;
          width: 100%;
          padding: 0 20px;
          background: url()
            no-repeat left top / 100% 100%;
          height: 52px;
          box-sizing: border-box;
          img {
            width: 20px;
            height: 20px;
            margin-right: 5px;
            vertical-align: middle;
            position: relative;
            object-fit: contain;
            top: 1px;
          }
        }
        .card-con {
          height: calc(100% - 52px);
          background: linear-gradient(
            164deg,
            #ffffff 0%,
            #ffffff 50%,
            #eff3fd 100%
          );
          border-radius: 12px;
          .text {
            padding: 24px 25px 0;
            margin: 0 0 24px;
            .desc {
              font-size: 12px;
              font-family: PingFang SC-Regular, PingFang SC;
              font-weight: 400;
              color: #2b2b2b;
              margin-bottom: 12px;
              &::before {
                content: "";
                display: inline-block;
                width: 5px;
                height: 5px;
                background: #c3c1f7;
                border-radius: 50%;
                margin-right: 6px;
                vertical-align: middle;
              }
            }
          }
          .btn {
            width: 90px;
            height: 32px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            opacity: 1;
            border: 1px solid #e1e0fc;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-family: PingFang SC-Medium, PingFang SC;
            font-weight: 500;
            color: #6965ea;
            cursor: pointer;
            margin-left: 119px;
          }
        }
      }
    }
  }
}
</style>
